import { NextRequest } from 'next/server';
import { withMiddleware } from '@/lib/middleware/entry';
import { successResponse, errorResponse } from '@/lib/response';
import { prisma } from '@/lib/prisma';
import { authenticateRequest } from '@/utils/auth';

async function handler(req: NextRequest) {
  const authResult = await authenticateRequest(req);
  if (!authResult.success) {
    return errorResponse(authResult.error || '身份验证失败');
  }

  const contents = await prisma.content.findMany({
    include: {
      categories: {
        include: {
          category: true,
        },
      },
    },
  });
  return successResponse(contents);
}

export const POST = withMiddleware(handler);